package com.czk.service.impl;

import com.czk.domain.User;
import com.czk.service.UserRepository;
import com.czk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/4/26 10:56
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserRepository userRepository;

    @Override
    public void save(User user) {
        userRepository.save(user);
    }

    @Override
    public void deleteById(String id) {
        userRepository.deleteById(id);
    }

    @Override
    public User queryUserById(String id) {
        Optional<User> optional = userRepository.findById(id);

        return optional.get();
    }

    @Override
    public Iterable<User> queryAll() {
        Iterable<User> userIterable = userRepository.findAll();
        return userIterable;
    }

    @Override
    public Page<User> findByName(String name, PageRequest request) {
        return userRepository.findByName(name, request);
    }
}
